<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <input id="channelid" name="channelid" type="hidden" th:value="${channelid}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">产品名称：</label>
                            <div class="col-sm-8">
                                <select onchange="getDistrict();" id="productid" name="productid" class="form-control"
                                        type="text">
                                    <option value="">---请选择---</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">链接名称：</label>
                            <div class="col-sm-8">
                                <input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')"
                                       maxlength="30" id="linkname"
                                       name="linkname" class="form-control"
                                       type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否模板：</label>
                            <div class="col-sm-8">
                                <select id="ischanneltemplate" name="ischanneltemplate"
                                        class="form-control">
                                    <option value="0">否</option>
                                    <option value="1">是</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">产品状态：</label>
                            <div class="col-sm-8">
                                <select id="state" name="state"
                                        class="form-control">
                                    <option value="1">正常</option>
                                    <option value="0">删除</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">选择产品模板：</label>
                            <div class="col-sm-8">
                                <select id="productidischanneltemplate" name="productidischanneltemplate"
                                        class="form-control" type="text"></select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">结算方式：</label>
                            <div class="col-sm-8">
                                <select onchange="getControlquantity()" id="settlementmethod" name="settlementmethod"
                                        class="form-control">
                                    <option value="1">UV</option>
                                    <option value="2">CPM</option>
                                    <option value="3">CPS</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="aaaaaa">
                            <label class="col-sm-3 control-label">刊例价格：</label>
                            <div class="col-sm-8">
                                <input onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"
                                       onafterpaste="this.value=this.value.replace(/[^\d.]/g,'')"
                                       maxlength="12" id="settlementprice"
                                       name="settlementprice" class="form-control"
                                       type="text">
                            </div>
                        </div>
                        <div class="form-group" id="bbbbbb">
                            <label class="col-sm-3 control-label">结算比例：</label>
                            <div class="col-sm-8">
                                <input onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"
                                       maxlength="10" id="channelsettlementrate"
                                       name="channelsettlementrate"
                                       type="text" placeholder="渠道分成">：
                                <input onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"
                                       maxlength="10" id="platformsettlementrate"
                                       name="platformsettlementrate"
                                       type="text" placeholder="平台分成">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">备注：</label>
                            <div class="col-sm-8">
                                <input maxlength="1024" id="description" name="description" class="form-control"
                                       type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript" src="/js/appjs/market/productChannelRelationship/add.js">
</script>
<script type="text/javascript" th:inline="javascript">
    $(function () {
        $.ajax({
            type: 'get',
            url: '/market/productChannel/listAllProduct?channelid=' + $("#channelid").val(),
            dataType: 'json',
            success: function (datas) {
                //返回list数据并循环获取
                var select = $("#productid");
                for (var i = 0; i < datas.length; i++) {
                    select.append("<option value='" + datas[i].id + "'>"
                        + datas[i].productName + "</option>");
                }
            }
        });
        $("#aaaaaa").hide();
        $("#bbbbbb").hide();

    })

    function getControlquantity() {
        $("#settlementprice").val('');
        $("#channelsettlementrate").val('');
        $("#platformsettlementrate").val('');
        var settlementmethod = $("#settlementmethod").val();
        if (settlementmethod == 1 || settlementmethod == 2) {
            $("#aaaaaa").show();
            $("#bbbbbb").hide();
        } else if (settlementmethod == 3) {
            $("#aaaaaa").hide();
            $("#bbbbbb").show();
        } else {
            $("#aaaaaa").hide();
            $("#bbbbbb").hide();
        }
    }

    function getDistrict() {
        $("#productidischanneltemplate").empty();    //清空二级下拉框，否则会叠加
        // $("#sdkid").append("<option value='' selected='selected'>" + "---请选择---" + "</option>");
        /* var id = obj.id;
         var options = $("#" + id + " option:selected"); //获取选中的项
         alert(options.text()); //拿到选中项的值
         var countrycode = options.val();*/
        var productid = $("#productid").val();
        $.ajax({
            type: "post",
            url: '/market/productChannel/listChannelTemplate',
            dataType: 'json',
            data: {
                productId: productid,
                channelid: $("#channelid").val(),
            },
            success: function (data) {
                var select = $("#productidischanneltemplate");
                select.append("<option value='" + '' + "'>"
                    + '---请选择---' + "</option>");
                for (var i = 0; i < data.length; i++) {
                    select.append("<option value='" + data[i].id + "'>"
                        + data[i].productName + "</option>");
                }
            }
        });
    }
</script>
</body>
</html>
